package com.guanyong.services;

import com.guanyong.dao.IBannerDaoMapper;
import com.guanyong.model.BannerListModel;
import com.guanyong.model.FilmModel;
import com.guanyong.utils.Cache.ICahce.ICache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/5/31.
 * 价格业务
 */
@Service
public class BannerListService {
    @Autowired
    IBannerDaoMapper iBannerDaoMapper;

    @Autowired
    FilmServices filmServices;

    public List<BannerListModel> GetAll(){
        return  iBannerDaoMapper.GetBannerAllList();
    }

    public BannerListModel GetBannerByid(Integer id){

        return  iBannerDaoMapper.GetBannerModelById(id);
    }

    public Integer UpdateBanner(BannerListModel bannerListModel){
        return  iBannerDaoMapper.update(bannerListModel);
    }


    public Integer AddBanner(BannerListModel bannerListModel){
        return  iBannerDaoMapper.insert(bannerListModel);
    }

    public Integer UpdateIntime(Integer id){
        return  iBannerDaoMapper.UpdateTime(id);
    }



    public Integer DleteBanner(Integer id){
        return  iBannerDaoMapper.delete(id);
    }


    public HashMap<String,Object> GetByBannerFilmList(int limit) {
        List<BannerListModel> bannerList= iBannerDaoMapper.GetBannerList(limit);
        List<FilmModel> list = new ArrayList<FilmModel>();
        for (BannerListModel bannerListModel :bannerList){
            FilmModel object= filmServices.GetFilmModelById(bannerListModel.getfUrl());
            if (object!=null) {
                list.add(object);
            }

        }
        HashMap<String,Object> hashMap=new HashMap();
        hashMap.put("list",list);

        return  hashMap;
    }
}
